<template>
  <div class="elderly-home-container">
    <!-- 主要内容区域 -->
    <div class="main-content">

      <!-- 轮播图区域 -->
      <el-carousel :interval="5000" arrow="always" height="400px" class="main-carousel">
        <el-carousel-item v-for="(item, index) in banners" :key="index">
          <img :src="item.avatar" :alt="item.name" class="carousel-avatar">
          <div class="carousel-caption">
            <h3>{{ item.name }}</h3>
            <p>{{ item.description }}</p>
          </div>
        </el-carousel-item>
      </el-carousel>

      <!-- 快速入口 -->
      <div class="quick-actions">
        <el-row :gutter="20">
          <el-col :span="6" v-for="(action, index) in quickActions" :key="index">
            <el-card shadow="hover" class="action-card" @click.native="handleQuickAction(action.path)">
              <div class="action-icon">
                <i :class="action.icon" style="color: #566048;"></i>
              </div>
              <h3>{{ action.name }}</h3>
              <p>{{ action.description }}</p>
            </el-card>
          </el-col>
        </el-row>
      </div>

      <!-- 公告和活动区域 -->
      <div class="notice-news-section">
        <el-row :gutter="20" style="padding-bottom: 20px;">
          <!-- 公告区域 -->
          <el-col :span="12">
            <el-card class="notice-board" shadow="hover">
              <div slot="header" class="clearfix">
                <el-row type="flex" align="middle" justify="space-between">
                  <span class="section-name"><i class="el-icon-megaphone"></i> 最新公告</span>
                  <el-button type="text" @click="viewMoreNotices">查看更多</el-button>
                </el-row>
              </div>
              <el-timeline>
                <el-timeline-item
                    v-for="(notice, index) in notices"
                    :key="index"
                    :timestamp="notice.date"
                    placement="top">
                  <el-card shadow="hover" class="notice-item" @click.native="viewNoticeDetail(notice.id)">
                    <h4>{{ notice.title }}</h4>
                    <p class="notice-content">{{ notice.content }}</p>
                    <div class="notice-footer">
                      <el-tag class="notice-type" :class="'type-'+notice.type">{{ notice.type }}</el-tag>
                      <el-tag class="notice-publisher">{{ notice.current }}</el-tag>
                    </div>
                  </el-card>
                </el-timeline-item>
              </el-timeline>
            </el-card>
          </el-col>

          <!-- 活动区域 -->
          <el-col :span="12">
            <el-card class="news-board" shadow="hover">
              <div slot="header" class="clearfix">
                <el-row type="flex" align="middle" justify="space-between">
                  <span class="section-name"><i class="el-icon-date"></i> 中医文化</span>
                  <el-button type="text" @click="viewMoreActivities">查看更多</el-button>
                </el-row>
              </div>
              <el-row :gutter="20" class="news-list">
                <el-col :span="12" v-for="(news, index) in newss" :key="index">
                  <el-card shadow="hover" class="news-item" :body-style="{ padding: '0px' }"
                           @click.native="viewActivityDetail(news.id)" style="margin-bottom: 10px;">
                    <img :src="news.avatar" class="news-avatar" style="height: 140px;object-fit: cover;">

                    <h4 style="padding: 5px 10px;">{{ news.title }}</h4>
                    <el-tag style="margin-left: 10px;" size="small">
                      <i class="el-icon-time"></i> {{ news.current }}
                    </el-tag>

                    <div class="news-info">
                      <div class="notice-content" style="padding: 0 10px;">{{ news.content }}</div>
                      <div class="news-meta" style="padding: 5px 10px;">
                      </div>
                    </div>
                  </el-card>
                </el-col>
              </el-row>
            </el-card>
          </el-col>
        </el-row>
      </div>

      <!-- 留言板区域 -->
      <!--      <div class="message-board">-->
      <!--        <el-card shadow="hover">-->
      <!--          <div slot="header" class="clearfix">-->
      <!--            <span class="section-name"><i class="el-icon-chat-dot-round"></i> 留言板</span>-->
      <!--            <el-button style="margin-left: 20px;" type="primary" size="small" @click="showMessageDialog">我要留言-->
      <!--            </el-button>-->
      <!--          </div>-->
      <!--          <el-table-->
      <!--              :data="messages"-->
      <!--              style="width: 100%"-->
      <!--              :default-sort="{prop: 'date', order: 'descending'}"-->
      <!--              class="message-table">-->
      <!--            <el-table-column-->
      <!--                prop="content"-->
      <!--                align="center"-->
      <!--                label="留言内容"-->
      <!--                width="500">-->
      <!--            </el-table-column>-->
      <!--            <el-table-column-->
      <!--                prop="user"-->
      <!--                align="center"-->
      <!--                label="留言人"-->
      <!--                width="120">-->
      <!--            </el-table-column>-->
      <!--            <el-table-column-->
      <!--                prop="date"-->
      <!--                label="留言时间"-->
      <!--                align="center"-->
      <!--                sortable-->
      <!--                width="180">-->
      <!--            </el-table-column>-->
      <!--            <el-table-column-->
      <!--                prop="status"-->
      <!--                align="center"-->
      <!--                label="留言状态">-->
      <!--            </el-table-column>-->
      <!--          </el-table>-->
      <!--        </el-card>-->
      <!--      </div>-->

    </div>

    <!-- 留言对话框 -->
    <!--    <el-dialog name="发表留言" :visible.sync="messageDialogVisible" width="50%">-->
    <!--      <el-form :model="messageForm" :rules="messageRules" ref="messageForm">-->
    <!--        <el-form-item label="留言内容" prop="content">-->
    <!--          <el-input type="textarea" v-model="messageForm.content" :rows="4"></el-input>-->
    <!--        </el-form-item>-->
    <!--      </el-form>-->
    <!--      <span slot="footer" class="dialog-footer">-->
    <!--        <el-button @click="messageDialogVisible = false">取 消</el-button>-->
    <!--        <el-button type="primary" @click="submitMessage">确 定</el-button>-->
    <!--      </span>-->
    <!--    </el-dialog>-->
  </div>
</template>

<script>
import {getCache, setCache} from "@/utils/useCache";
import api from "@/api";

export default {
  name: "ElderlyHome",
  data() {
    return {
      userInfo: getCache('USERINFO'),
      banners: [
        {
          avatar: require("@/assets/swapper/jhk-1746197233390.jpg"),
          name: "与时俱进、守正创新。",
          description: "数字科技赋能传统医药文化传承"
        },
        {
          avatar: require("@/assets/swapper/jhk-1746198893611.png"),
          name: "调节情绪，预防疾病",
          description: "结合大预言模型提供交互能力，建立良好的健康观念"
        },
        {
          avatar: require("@/assets/swapper/jhk-1746198770845.png"),
          name: "打破界限，传承传统。",
          description: "共同关注传统文化，传播文化传承文化"
        }
      ],
      quickActions: [
        {
          icon: "el-icon-date",
          name: "系统公告",
          description: "查看系统最新公告",
          path: "/user/notice"
        },
        {
          icon: "el-icon-chat-line-round",
          name: "中医文化",
          description: "查看系统中医文化",
          path: "/user/news"
        },
        {
          icon: "el-icon-notebook-2",
          name: "中药常识",
          description: "查看系统中药常识",
          path: "/user/model"
        },
        {
          icon: "el-icon-user",
          name: "健康档案",
          description: "管理个人健康档案",
          path: "/user/mine"
        }
      ],
      notices: [],
      newss: [],
      messages: [],
      messageDialogVisible: false,
      messageForm: {
        "content": "",
        "user": getCache('USERINFO').id
      },
      messageRules: {
        content: [
          {required: true, message: "请输入留言内容", trigger: "blur"},
          {min: 10, max: 500, message: "长度在 10 到 500 个字符", trigger: "blur"}
        ]
      }
    };
  },
  mounted() {
    api.news.newsList().then(r => {
      this.newss = r.data.data.slice(0, 4);
    })
    api.notice.noticeList().then(r => {
      this.notices = r.data.data.slice(0, 3);
    })
    // api.feed.feedList().then(r => {
    //   this.messages = r.data.data;
    // })
  },
  methods: {
    handleQuickAction(path) {
      setCache('CURRENT_MENU', path);
      this.$router.push(path);
    },
    viewMoreNotices() {
      this.$router.push("/user/notice");
    },
    viewMoreActivities() {
      this.$router.push("/user/news");
    },
    viewNoticeDetail(id) {
      this.$router.push(`/user/notice_detail?id=${id}`);
    },
    viewActivityDetail(id) {
      this.$router.push(`/user/news_detail?id=${id}`);
    },
    showMessageDialog() {
      this.messageDialogVisible = true;
    },
    // submitMessage() {
    //   this.$refs.messageForm.validate(valid => {
    //     if (valid) {
    //       api.feed.feedAppend(this.messageForm).then(r => {
    //         console.log(r);
    //         this.$message.success("留言提交成功");
    //         this.messageDialogVisible = false;
    //         this.messageForm.content = "";
    //         api.feed.feedList().then(res => {
    //           this.messages = res.data.data;
    //         })
    //       })
    //     }
    //   });
    // }
  }
};
</script>

<style scoped>
.elderly-home-container {
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", Arial, sans-serif;
  background-color: #f5f7fa;
  min-height: 100vh;
}

.main-header {
  background-color: #fff;
  color: white;
  height: 60px !important;
  line-height: 60px;
  padding: 0 20px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
}

.logo-area {
  display: flex;
  align-items: center;
}

.logo {
  height: 40px;
  margin-right: 10px;
}

.logo-area h1 {
  color: white;
  font-size: 20px;
  margin: 0;
}

.main-menu {
  flex: 1;
  margin: 0 20px;
  border-bottom: none;
}

.user-info {
  display: flex;
  align-items: center;
}

.user-name {
  margin-left: 10px;
  color: white;
}

.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 20px 0;
}

.main-carousel {
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.carousel-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.carousel-caption {
  position: absolute;
  bottom: 40px;
  left: 40px;
  color: white;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
}

.carousel-caption h3 {
  font-size: 28px;
  margin-bottom: 10px;
}

.quick-actions {
  margin: 30px 0;
}

.action-card {
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
}

.action-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

.action-icon {
  font-size: 36px;
  color: #409EFF;
  margin: 15px 0;
}

.action-card h3 {
  margin: 10px 0;
  color: #303133;
}

.action-card p {
  color: #909399;
  font-size: 14px;
  margin-bottom: 15px;
}

.notice-news-section {
  margin: 30px 0;
}

.section-name {
  font-size: 18px;
  font-weight: bold;
  color: #303133;
}

.notice-board, .news-board {
  height: 100%;
}

.notice-item {
  cursor: pointer;
  margin-bottom: 10px;
}

.notice-content {
  font-size: 13px;
  color: #909399;
  margin: 10px 0;
  height: 36px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.notice-publisher {
  margin-left: 10px;
}
</style>